const app = getApp(); //引入自定义头部导航

import { Opinion } from 'opinionDetail_model.js';
var opinion = new Opinion();
var name = '';
Page({
  data: {
    showIcon: true,
    //显示返回键以及首页 
    currentTab: '0',
    //默认选择投诉
    way: '',
    dec: '',
    showMessage: false
  },
  onLoad: function (options) {
    console.log(options);
    name = options;
  },
  typeTab: function (e) {
    //点击切换
    var that = this;

    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      });
    }
  },
  //分享
  onShareAppMessage: function () {
    util.sharePage();
  },
  //获取问题描述
  getDec: function (e) {
    var val = e.detail.value;
    this.setData({
      dec: val
    });
  },
  //获取联系方式
  getWay: function (e) {
    var val = e.detail.value;
    this.setData({
      way: val
    });
  },
  //提交
  opinionBtn: function (e) {
    var _type = e.target.dataset.current;
    var dec_len = this.data.dec.length;
    var question = this.data.currentTab; //问题类型

    var describe = this.data.dec; //问题描述

    var _way = this.data.way; //联系方式

    var telRule = /^(13[0-9]|14[5-9]|15[012356789]|166|17[0-8]|18[0-9]|19[1|3|5|8|9])[0-9]{8}$/;
    var qqRule = /^[1-9]\d{4,9}$/;

    if (dec_len < 5 || dec_len > 200) {
      this.showMessage('请输入5-200字的内容！');
    } else if (_way == "") {
      this.showMessage('请输入您的手机号或QQ号！');
    } else if (!telRule.test(_way) && !qqRule.test(_way)) {
      this.showMessage('您的手机号或QQ号输入有误！');
    } else {
      name = name['name'];
      opinion.getfankui(question, describe, _way, name, res => {
        console.log(res);
        tt.redirectTo({
          url: '../ycOrder/ycOrder'
        });
        this.showMessage('提交成功');
      });
    }
  },
  queHuo: function (e) {
    console.log(e);
  },
  showMessage: function (text) {
    var that = this;
    that.setData({
      showMessage: true,
      messageContent: text
    });
    setTimeout(function () {
      that.setData({
        showMessage: false,
        messageContent: ''
      });
    }, 3000);
  }
});